#!/bin/bash

if [ $# -eq 0 ]; then
    echo "错误：缺少参数"
    exit 1
fi

if [ -f $1 ]; then
    cat $1
elif [ -z "$(file -b $1 | grep compressed)" ]; then
    echo "错误：参数不是普通文件或压缩文件"
    exit 1
elif [ -f "${1%.*}" ]; then
    echo "错误：同名文件已存在"
    exit 1
elif [ -d $1 ]; then
    tar -czvf "${1%/}.tar.gz" $1
else
    tar -xzvf $1
fi